package com.boot.mall.search.controller;

import com.boot.common.to.es.SkuEsModel;
import com.boot.common.utils.R;
import com.boot.mall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/search/save")
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    @PostMapping("product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels){
        try {
            boolean b = productSaveService.productStatusUp(skuEsModels);
            if (!b){
                return R.error("商品上架失败！");
            }
        } catch (IOException e) {
            log.error("Elastic Search连接失败！");
            return R.error("系统故障!");
        }
        return R.ok();
    }

}
